#include "bithashtablehandle.h"
#include "bittable.h"

BitHashTableHandle::BitHashTableHandle(BitTable *table)
    : m_table(table)
{
    m_seeds[0] = 3;
    m_seeds[1] = 5;
    m_seeds[2] = 7;
    m_seeds[3] = 11;
    m_seeds[4] = 13;
    m_seeds[5] = 31;
    m_seeds[6] = 37;
    m_seeds[7] = 61;
}

void BitHashTableHandle::setBit(const Hashable &obj)
{
    for (int i = 0; i < 8; i ++)
        m_table->setBitValue(obj.hashCode(m_seeds[i]));
}

void BitHashTableHandle::clearBit(const Hashable &obj)
{
    for (int i = 0; i < 8; i ++)
        m_table->clearBitValue(obj.hashCode(m_seeds[i]));
}

bool BitHashTableHandle::testBit(const Hashable &obj)
{
    for (int i = 0; i < 8; i ++) {
        bool ret = m_table->getBitValue(obj.hashCode(m_seeds[i]));
        if (!ret)
            return ret;
    }

    return true;
}

void BitHashTableHandle::clear()
{
    m_table->clear();
}

